#!/bin/bash
# shellcheck source=meta-facebook/recipes-fb/obmc_functions/files/fb-common-functions
source /usr/libexec/fb-common-functions

GPIO_HIGH=1
GPIO_LOW=0

LINENAME="$1"
STATE="$2"

do_RUN_POWER_PG_change()
{
    if [ "$STATE" = "assert" ]; then
        set_gpio "PCI_MUX_SEL" "$GPIO_HIGH"
        busctl set-property xyz.openbmc_project.State.Host0 /xyz/openbmc_project/state/host0 xyz.openbmc_project.State.Host CurrentHostState s xyz.openbmc_project.State.Host.HostState.Running
    else
        set_gpio "PCI_MUX_SEL" "$GPIO_LOW"
        busctl set-property xyz.openbmc_project.State.Host0 /xyz/openbmc_project/state/host0 xyz.openbmc_project.State.Host CurrentHostState s xyz.openbmc_project.State.Host.HostState.Off
    fi
}

do_ID_RST_BTN_BMC_N_change()
{
    if [ "$STATE" = "assert" ]; then
        set_gpio "RST_BMC_RSTBTN_OUT_N" "$GPIO_HIGH"
    else
        set_gpio "RST_BMC_RSTBTN_OUT_N" "$GPIO_LOW"
    fi
}

case $LINENAME in
    "RUN_POWER_PG" | "ID_RST_BTN_BMC_N")
        FUNC_NAME="do_${LINENAME}_change"
        "$FUNC_NAME"
        ;;
    *)
        echo "Unknown LINENAME = $LINENAME"
        exit 1
        ;;
esac
